package itheima.d11;

import java.util.Scanner;

import static java.util.Arrays.binarySearch;

//查找算法
public class Test {
    public static void main(String[] args) {
        //二分查找/折半查找
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要查找的数字：");
        int find = scanner.nextInt();


        int[] arr = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
        extracted(arr, find);


    }

    private static int extracted(int[] arr, int find) {
        int resukt = -1;
        int left = 0;
        int right = arr.length - 1;

        while (left <= right) {
            int mid = (left + right) / 2;
            if (arr[mid] == find) {

                System.out.println(mid);
         return mid;
            } else if (arr[mid] > find) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }

        }
        System.out.println(resukt);
        return -1;
    }

}
